home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 006 (1987-02-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 006 (1987-02-15)(Ossowski, Stefan)(DE)(PD).adf / IconExec / IconExec.c < prev    next >
C/C++ Source or Header  |  1987-03-04  |  5KB  |  148 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /* ICONEXEC (c) Copyright 1986 John A. Toebes, VIII. All rights reserved */
  3. /*  This program may be used and modified for any purpose so long as     */
  4. /*  this copyright notice remains with the code and the program is not   */
  5. /*  sold and no charge is made for its use.  For permission to           */
  6. /*  incorporate this into a commercial product, contact the author:      */
  7. /*    John A. Toebes, VIII                                               */
  8. /*    120 H Northington Place                                            */
  9. /*    Cary NC 27511                                                      */
  10. /*    (919) 469-4210                                                     */
  11. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  12.  
  13. /*-----------------------------------------------------------------------*/
  14. /* This program allows you to associate any series of CLI commands to be */
  15. /* run when you click on an ICON even though there is no CLI window open */
  16. /* One problem associated with it is that a program that does input from */
  17. /* the default input (*) always sees EOF.  I am researching why this     */
  18. /* happens, but believe it is related to an AmigaDos problem.            */
  19. /*-----------------------------------------------------------------------*/
  20.  
  21. /****************
  22.   To compile this program under Lattice C:
  23.     1) Compile the 
  24.     LC1 -oRAM: -i<includedir> ICONEXEC
  25.     LC2 -v -oICONEXEC.O RAM:ICONEXEC
  26.  
  27.     2) Create a file 'link_iconexec' with the linker commands (assuming 
  28.        that df0:lib contains the appropriate linking modules):
  29.     FROM     df0:lib/c.o+*
  30.     IconExec.o
  31.     TO       IconExec
  32.     LIBRARY  df0:lib/lc.lib+df0:lib/amiga.lib
  33.     MAP      nil:
  34.  
  35.     3) link it using alink
  36.     ALINK WITH LINK_ICONEXEC
  37.  
  38.    To create and execute a user customized Icon Exec
  39.  
  40.     1) Create an Icon (copy the CLI Icon) for IconExec
  41.  
  42.     2) Run the SetWindow program to set a the tool window on the Icon
  43.     SETWINDOW ICONEXEC "CON:0/0/100/100/MYWINDOW"
  44.        If you do not do this, then by default ICONEXEC will open a full
  45.        screen window with a title of "ICONEXEC by John A. Toebes, VIII"
  46.  
  47.     3) Using the Workbench INFO meno option, enter the commands into the
  48.        tool types window.
  49.  
  50.     4) Click on the Icon and watch it go.
  51. **********/
  52.  
  53. #include <stdio.h>
  54. #include <exec/types.h>
  55. #include <workbench/workbench.h>
  56. #include <workbench/icon.h>
  57. #include <workbench/startup.h>
  58. #include <libraries/dos.h>
  59. #include <libraries/dosextens.h>
  60.  
  61. #define DEFAULT_WINDOW "CON:0/1/640/199/ICONEXEC by John A. Toebes, VIII"
  62.  
  63. LONG IconBase;
  64. extern struct WBStartup *WBenchMsg;
  65.  
  66. _main(line)
  67. char *line;
  68. {
  69.     char **tools;
  70.     char *thistool;
  71.     struct WBArg *wbarg;
  72.     struct DiskObject *diskobj, *GetDiskObject();
  73.     int olddir;
  74.     char *window;
  75.     struct FileHandle *handle;
  76.     BPTR file;
  77.     struct Process *process;
  78.  
  79.     if ( (IconBase = OpenLibrary( ICONNAME, 1) ) == NULL)
  80.         {
  81.         diag("Cannot open Icon Library", NULL);
  82.         _exit(2);
  83.         }
  84.  
  85.     /* Locate the first argument passed from workbench */
  86.     wbarg    = WBenchMsg->sm_ArgList;
  87.  
  88.     /* change to its home dir */
  89.     olddir    = CurrentDir( wbarg->wa_Lock );
  90.  
  91.     /* read in its disk object structure */
  92.     diskobj    = GetDiskObject( wbarg->wa_Name );
  93.  
  94.     /* did we have a default tool window opened for us ? */
  95.     if (WBenchMsg->sm_ToolWindow == NULL)
  96.         {
  97.         /* figure out the window to open */
  98.         if ( (window = diskobj->do_ToolWindow) == NULL)
  99.             window = DEFAULT_WINDOW;
  100.  
  101.         /* open the desired window if we can */
  102.         if ( (file = Open(window,MODE_OLDFILE)) == NULL)
  103.             {
  104.             diag("Cannot open Icon Window", window);
  105.             CurrentDir( olddir );
  106.             CloseLibrary( IconBase );
  107.             _exit(4);
  108.             }
  109.  
  110.         /* fool system into thinking we have a CLI based window */
  111.         handle = (struct FileHandle *)(file << 2);
  112.         process = (struct Process *)FindTask(0);
  113.         process->pr_ConsoleTask = (APTR)handle->fh_Type;
  114.         }
  115.     else
  116.         file = Output();
  117.  
  118.     /* run through the tools and execute them one at a time */
  119.     for (tools = diskobj->do_ToolTypes; thistool=*tools; tools++)
  120.         Execute(thistool, NULL, NULL);
  121.  
  122.     /* close down the window */
  123.     if (WBenchMsg->sm_ToolWindow == NULL)
  124.         Close(file);
  125.  
  126.     /* restore the previous directory */
  127.     CurrentDir( olddir );
  128.     CloseLibrary( IconBase );
  129.     _exit(0);
  130. }
  131.  
  132. diag(msg, parm)
  133. char *msg;
  134. char *parm;
  135. {
  136.     BPTR logfile;
  137.     char c;
  138.  
  139.     logfile = Open("con:0/0/50/200/ICONEXEC Error", MODE_OLDFILE);
  140.     Write(logfile, "ICONEXEC Error:\n", 16);
  141.     Write(logfile, msg, strlen(msg));
  142.     if (parm != NULL)
  143.         Write(logfile, parm, strlen(parm));
  144.     Write(logfile, "Press <RETURN> to continue\n", 27);
  145.     Read(logfile, &c, 1);
  146.     Close(logfile);
  147. }
  148.